﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Admin.Controls
{
    public partial class EditHuongdan : System.Web.UI.UserControl
    {
        public int idhuongdan;
        public string namehuongdan;
        public string noidung;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                idhuongdan = Convert.ToInt32(Request.QueryString["huongdanid"]);
                DataTable dt = DAL.DCollector.DBCollector.Instance.StoredProcedureSelectWhereByID("tbl_HuongDan", "*", "HuongDan_ID", idhuongdan, "selectwhereid");
                namehuongdan = dt.Rows[0]["HuongDan_Name"].ToString();
                noidung = dt.Rows[0]["HuongDan_Descriptions"].ToString();
                txtNameHuongdan.Text = namehuongdan;
                CKEditorHuongdan.Text = noidung;
            }
            catch (Exception)
            {
                Response.Redirect("/error.htm");
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {

            if (txtNameHuongdan.Text != "")
            {
                if (CKEditorHuongdan.Text != "")
                {
                    string name = txtNameHuongdan.Text;
                    string noidung = CKEditorHuongdan.Text;
                    DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[2];
                    cl[0] = new DAL.DHelpers.Column("HuongDan_Name", name, DAL.DHelpers.DataType.DataTypeSql.Varchar);
                    cl[1] = new DAL.DHelpers.Column("HuongDan_Descriptions", noidung, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);

                    string[] colWhere = new string[1];
                    colWhere[0] = "HuongDan_ID";

                    object[] colValue = new object[1];
                    colValue[0] = idhuongdan;

                    DAL.DCollector.DBCollector.Instance.Update("tbl_HuongDan", cl, colWhere, colValue);
                    Response.Redirect("/Admin/Index.aspx?panel=7&sub=4");
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng nhập tên hướng dẫn...')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Vui lòng nhập nội dung hướng dẫn...')</script>");
            }

        }
    }
}